<?php

namespace app\index\controller;

use think\facade\View;

class Member
{

    public function index()
    {
        $keyword = get_param('keyword');
        View::assign('keyword', $keyword);
        return View::fetch();
    }

    public function getList()
    {
        $memberModel = new \app\common\model\Member();
        $data = $memberModel->select();
        $count = $memberModel->count();
        output_data_table($data, $count);
    }

    public function add()
    {
        $mobile = post_param('mobile');
        $name = post_param('name');
        $age = post_param('age');
        if (empty($mobile)) return View::fetch();
        $memberModel = new \app\common\model\Member();
        //数据校验
        $data = $memberModel->where('member_mobile', '=', $mobile)->find();
        if (!empty($data)) output_error('此号码已存在~');
        //插入数据
        $data = array();
        $data['member_mobile'] = $mobile;
        $data['member_name'] = $name;
        $data['member_age'] = $age;
        $data['add_time'] = time();
        $memberModel->insert($data);
        output_success();
        return null;

    }

    public function delete()
    {
        $id = get_param('id');
        $memberModel = new \app\common\model\Member();
        $memberModel->where('member_id', '=', $id)->delete();
        output_success();
    }

}
